package com.zp.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

public class StreamTest {
	public static void main(String[] args) throws IOException {
		OutputStream os = new FileOutputStream("D:/lisi/zpp.txt");
		OutputStreamWriter osw = new OutputStreamWriter(os);
		BufferedWriter bw = new BufferedWriter(osw);
		
		bw.write("http://www.google.com");
		bw.write("\n");
		bw.write("\n");
		bw.write("http://www.baidu.com");
		
		bw.close();
		
		InputStream is = new FileInputStream("D:/lisi/zpp.txt");
		InputStreamReader isd = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isd);
		
		/**
		 * readLine:读取一行数据，没有数据时返回null；
		 * 但是使用bw.write("\n");产生的空行不返回null；
		 */
//		System.out.println(br.readLine());
//		System.out.println(br.readLine());
//		System.out.println(br.readLine());
		
		/**
		 * 有上述可知：可以通过判断null != br.readLine();
		 * 来解决未知行数的数据的循环；
		 */
		String str = br.readLine();
		while(null != str){
			System.out.println(str);
			str = br.readLine();
		}
		br.close();
	}
}
